package last.project;

import java.util.ArrayList;

import gameView.GameDrawView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class HighScoreScreen extends Activity {
	private Context cxt;
	private int MAX_X, MAX_Y;
	
	private ArrayList<String> Names;
	private ArrayList<Integer> Scores;
	
	private ArrayList<TextView> ViewNames, ViewScores;
	private ScrollView Table;
	private Button PlayAgain, MainMenu;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        cxt=this;
        setContentView(R.layout.gameoverlayout);
        
        setupLayout();
        setupButtons();
	}
	private void setupLayout() {
		MAX_X=FinalProjectActivity.MAX_X;
		MAX_Y=FinalProjectActivity.MAX_Y;
		Names = FinalProjectActivity.HSSystem.Names;
		Scores = FinalProjectActivity.HSSystem.Scores;
		ViewNames = new ArrayList<TextView>();
		ViewScores = new ArrayList<TextView>();
		
		AbsoluteLayout superLayout = (AbsoluteLayout) findViewById(R.id.AbsoluteLayout1);
        AbsoluteLayout.LayoutParams superParams;
        
        superParams = new AbsoluteLayout.LayoutParams(320, 90, MAX_X/2-160, MAX_Y/4-120);
        TextView Intro = new TextView(cxt);
        Intro.setText("High Scores");
        Intro.setTextSize(38);
        superLayout.addView(Intro, superParams);
        
        superParams = new AbsoluteLayout.LayoutParams(4*MAX_X/5, MAX_Y/2, MAX_X/10, MAX_Y/4);
        Table = new ScrollView(cxt);
        AbsoluteLayout tableLayout = new AbsoluteLayout(cxt);
        Table.addView(tableLayout);
        superLayout.addView(Table, superParams);
        
        
        AbsoluteLayout.LayoutParams tableParams;
        tableParams = new AbsoluteLayout.LayoutParams(2*MAX_X/5, 50, 0, 0);
    	TextView NameHeader = new TextView(cxt);
    	NameHeader.setText("Name");
    	NameHeader.setTextSize(26);
    	tableLayout.addView(NameHeader, tableParams);
    	tableParams = new AbsoluteLayout.LayoutParams(2*MAX_X/5, 50, 2*MAX_X/5, 0);
    	TextView ScoreHeader = new TextView(cxt);
    	ScoreHeader.setGravity(Gravity.RIGHT);
    	ScoreHeader.setText("Score ");
    	ScoreHeader.setTextSize(26);
    	tableLayout.addView(ScoreHeader, tableParams);
        
        
        for (int i=0 ;i<Scores.size(); i++) {
        	tableParams = new AbsoluteLayout.LayoutParams(2*MAX_X/5, 50, 0, 50*(i+1));
        	TextView ViewName = new TextView(cxt);
        	ViewName.setText(Names.get(i));
        	ViewName.setTextSize(26);
        	ViewNames.add(ViewName);
        	tableLayout.addView(ViewName, tableParams);
        	tableParams = new AbsoluteLayout.LayoutParams(2*MAX_X/5, 50, 2*MAX_X/5, 50*(i+1));
        	TextView ViewScore = new TextView(cxt);
        	ViewScore.setGravity(Gravity.RIGHT);
        	ViewScore.setText(""+Scores.get(i)+" ");
        	ViewScore.setTextSize(26);
        	ViewScores.add(ViewScore);
        	tableLayout.addView(ViewScore, tableParams);
        }
        
        superParams = new AbsoluteLayout.LayoutParams(320, 60, MAX_X/2-160, 3*MAX_Y/4);
        PlayAgain = new Button(cxt);
        PlayAgain.setText("Retry");
        superLayout.addView(PlayAgain, superParams);
        
        superParams = new AbsoluteLayout.LayoutParams(320, 60, MAX_X/2-160, 3*MAX_Y/4+70);
        MainMenu = new Button(cxt);
        MainMenu.setText("Main Menu");
        superLayout.addView(MainMenu, superParams);
	}
	private void setupButtons() {
		View.OnClickListener restartGame = new View.OnClickListener() {
			public void onClick(View v) {
				Intent tent = new Intent(cxt, GameScreen.class);
        		cxt.startActivity(tent);
			}
		};
		View.OnClickListener toMainMenu = new View.OnClickListener() {
			public void onClick(View v) {
				Intent tent = new Intent(cxt, FinalProjectActivity.class);
        		cxt.startActivity(tent);
			}
		};
		
		PlayAgain.setOnClickListener(restartGame);
		MainMenu.setOnClickListener(toMainMenu);
	}
}
